#ifndef SESSINOFRIENDAREA_H
#define SESSINOFRIENDAREA_H

#include <QWidget>
#include <QScrollArea>
#include <QScrollBar>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QStyleOption>
#include <QPainter>
#include <QMouseEvent>
#include <QEnterEvent>

class SessionFriendItem;

enum ITEMTYPE {
    SESSIONITEMTYPE,
    FRIENDITEMTYPE,
    APPLYITEMTYPE
};

class SessinoFriendArea : public QScrollArea
{
    Q_OBJECT
public:
    explicit SessinoFriendArea(QWidget *parent = nullptr);

    void addItem(ITEMTYPE itemType, const QString& id,
                 const QIcon &avatar, const QString &name,const QString &text);

    void clear();

    void clickItem(int index);

private:
    QWidget* m_container;


signals:
};

///
/// 基类item
///
class SessionFriendItem: public QWidget
{
    Q_OBJECT
public:
    SessionFriendItem(QWidget* owner, const QIcon& avatar, const QString& name, const QString& text);

    void select();  // 选中更换样式之类的

    virtual void active() = 0;  // 用于特定对象调用不同的界面出来

private:
    void paintEvent(QPaintEvent *) override; // 自定义类的样式需要重写此函数才能生效
    void mousePressEvent(QMouseEvent* event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void enterEvent(QEnterEvent*) override;
    void leaveEvent(QEvent*) override;

protected:
    QLabel* m_textLabel = nullptr;  // 作为个性签名或者最新消息

private:
    QWidget* m_owner = nullptr;       // 属于哪个区域的，一般是SessionFriendArea
    bool m_isSelect = false;

};



///
/// \brief 会话消息类
///
class SessionItem: public SessionFriendItem{
public:
    SessionItem(QWidget* owner, const QString& chatSessionId, const QIcon& avatar,
                const QString& name, const QString& lastMessage);

    virtual void active() override;

    void updateLastMessage(const QString& chatSessionId);  // 更新最近一条消息

private:
    QString m_chatSessionId;  // 会话消息ID

};

///
/// \brief 好友列表类
///
class FriendItem: public SessionFriendItem{
public:
    FriendItem(QWidget* owner, const QString& userId, const QIcon& avatar,
                const QString& name, const QString& description);

    virtual void active() override;

private:
    QString m_userId;  // 好友ID

};

///
/// \brief 好友申请类
///
class ApplyItem: public SessionFriendItem{
public:
    ApplyItem(QWidget* owner, const QString& userId, const QIcon& avatar, const QString& name);

    virtual void active() override;

private:
    QString m_userId;  // 好友ID

};

#endif // SESSINOFRIENDAREA_H
